package com.apex.lottery.dao.mapper;

import com.apex.lottery.dao.dataobject.AwardDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName AwardMapper
 * @Description
 * @Author ZJX
 * @Date 2025/4/17 15:14
 * @Version 1.0
 **/

public interface AwardMapper {
    @Insert("insert into prize (name, image_url, price, description)" +
            " values (#{name}, #{imageUrl}, #{price}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insert(AwardDO awardDO);

    @Select("select count(*) from prize")
    int count();


    @Select("select * from prize order by id desc limit #{offset}, #{pageSize}")
    List<AwardDO> selectPrizeList(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);

    @Select("<script>" +
            " select id from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> ids);

    @Select("<script>" +
            " select * from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<AwardDO> batchSelectByIds(@Param("items") List<Long> ids);

    @Select("select * from prize where id = #{id}")
    AwardDO selectById(@Param("id") Long id);


}
